package nl.isaac.labs.mobile.client;

import java.util.logging.Level;
import java.util.logging.Logger;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.mobile.phonegap.DeviceReadyHandler;
import com.google.gwt.mobile.phonegap.PhoneGap;
import com.google.gwt.mobile.phonegap.api.Notification;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootLayoutPanel;

/**
 * The Class Sandbox.
 * 
 * @author Jeroen Brosens
 */
public class Sandbox implements EntryPoint, DeviceReadyHandler {
  static final Logger logger = Logger.getLogger("Sandbox");

  /*
   * (non-Javadoc)
   * 
   * @see com.google.gwt.core.client.EntryPoint#onModuleLoad()
   */
  @Override
  public void onModuleLoad() {
    logger.log(Level.INFO, "Module loaded.");

    PhoneGap.setDebugMode(true);
    PhoneGap.init(this);

    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
      @Override
      public void execute() {
        SlidePanelPage slidePanelPage = new SlidePanelPage();
        RootLayoutPanel.get().add(slidePanelPage);
      }
    });
  }

  private void runNativeStuff() {
    Notification.beep(1);
    Notification.alert("It works!", new Notification.Callback() {

      @Override
      public void onComplete() {
        Notification.vibrate(250);
      }
    }, "PhoneGap", "OK");
  }

  /*
   * (non-Javadoc)
   * 
   * @see com.google.gwt.mobile.phonegap.DeviceReadyHandler#onDeviceReady()
   */
  @Override
  public void onDeviceReady() {
    logger.log(Level.INFO, "Device ready.");

    // Button
    Button b = new Button("Run");
    b.setHeight("100px");
    b.setWidth("200px");
    b.addClickHandler(new ClickHandler() {

      @Override
      public void onClick(final ClickEvent event) {
        runNativeStuff();
      }
    });

    // RootLayoutPanel.get().add(b);
  }
}
